package com.example.mobile2121606109ycg0524homework1;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private Button btnMainAdd;
    private RecyclerView rvMainStaff;
    private List<Staff> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        list = new MyDataAdapter().QueryAll(this);

        rvMainStaff.setAdapter(new StaffRViewAdapter(list));

        btnMainAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, AddStaffActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        rvMainStaff.getAdapter().notifyDataSetChanged();
    }

    private void initView() {
        btnMainAdd = (Button) findViewById(R.id.btnMainAdd);
        rvMainStaff = (RecyclerView) findViewById(R.id.rvMainStaff);
        rvMainStaff.setLayoutManager(new LinearLayoutManager(this));
    }
}